import Pbf from "pbf";
import geobuf from "geobuf";
import Point from "ol/geom/Point";
import { fromLonLat } from "ol/proj.js";
import GeoJSON from "ol/format/GeoJSON.js";
import { deBase64 } from "@/utils/decode";
import * as coordinate from "ol/coordinate";
import LineString from "ol/geom/LineString";
import VectorLayer from "ol/layer/Vector.js";
import VectorSource from "ol/source/Vector.js";
import { getVectorContext } from "ol/render.js";
import VectorImageLayer from "ol/layer/VectorImage.js";
import { Circle, Text, Icon, Fill, Stroke, Style } from "ol/style.js";
import { TileArcGISRest, XYZ } from "ol/source.js";

import * as maputils from "./maputils";
import TileLayer from "ol/layer/Tile";

//加载省边界
const ChinaLayer = async (options) => {
  var layerid = "shenglayer";
  var ol2d = options.ol2d;

  const query = {
    tablename: "geo_sheng_polygon", //表名
  };
  if (options.data && options.data.dm) {
    query["filter"] = "xzqdm='" + options.data.dm + "'";
  }

  var options = {
    id: layerid,
    ol2d: ol2d,
    query: query,
    isFit: true,
    styleExt: { text: "xzqmc", colorIndex: "id" },
  };
  var tmplayer = await maputils.AddMapLayer(options);
  return tmplayer;
};

const addChinaLayer = (options) => {
  var vectorLayer = new VectorLayer({
    source: new VectorSource({
      url: "./china3857.geojson", // GeoJSON 文件路径
      format: new GeoJSON(), // 指定数据格式为 GeoJSON
    }), // 设置数据源为上面定义的 GeoJSON 数据源
  });
  ol2d.addLayer(vectorLayer);

  var vectorLayer = new VectorLayer({
    source: new VectorSource({
      url: "./china3857.geojson", // GeoJSON 文件路径
      format: new GeoJSON(), // 指定数据格式为 GeoJSON
    }), // 设置数据源为上面定义的 GeoJSON 数据源
  });
  ol2d.addLayer(vectorLayer);

  

  var xyzLayer = new TileLayer({
    source: new XYZ({
      url: 'http://www.vmscenter.com:10090/default/{z}/{x}/{y}.png'
    })
  });

  ol2d.addLayer(xyzLayer);

};

export { addChinaLayer };
